% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/plot_distance_mean_by_group.R
\name{distance_by_group1}
\alias{distance_by_group1}
\title{Get average distance for ONE demographic group versus everyone else}
\usage{
distance_by_group1(
  results_bybg_people,
  demogvarname = varlist2names("names_d")[1],
  demoglabel = fixcolnames(demogvarname, "r", "shortlabel")
)
}
\arguments{
\item{results_bybg_people}{data.table from doaggregate()$results_bybg_people}

\item{demogvarname}{e.g., "pctlowinc"}

\item{demoglabel}{e.g., "Low Income Residents"}
}
\value{
list of 2 numbers: avg_distance_for_group and avg_distance_for_nongroup
}
\description{
Get average distance for ONE demographic group versus everyone else
}
\details{
Note on Avg Distance and range of distances in each Demog group, & \%D as function of distance:

We have info on each blockgroup near each site, which means some small \% of those bgs are duplicated in this table:

\if{html}{\out{<div class="sourceCode">}}\preformatted{results_bybg_people
}\if{html}{\out{</div>}}

Mostly we want overall (not by site) to know avg and cum distrib of distances in each demog,

(and also \%D as a function of continuous distance),

and for those stats we would want to take only unique blockgroups from here,
using the shorter distance, so the distribution of distances does not doublecount people.

But we might also want to see that distribution of distances by D for just 1 site?

And we might also want to see the \%D as a function of continuous distance at just 1 site?

So to retain flexibility doaggregate() reports all instances of blockgroup-site pairings.
}
\examples{
 y <- ejamit(testpoints_100, radius = 3)
 
 # see barplot and table comparing groups to see which are closer to sites analyzed
 plot_distance_mean_by_group(y$results_bybg_people) # or distance_mean_by_group() synonym
 
 # table - proximity of sites for just one demog group vs rest of population
 print(distance_by_group(y$results_bybg_people,
   demogvarname = 'pctlowinc'))
   
 # plot cumulative share of group by distance vs overall population
  distance_by_group_plot(y$results_bybg_people,
     demogvarname = 'pctlowinc' )
     
 # plot cum. shares for two groups  
 # about 14\% of black and 12\% of asian residents have a site within 1 mile. 
 # 29\% vs 21\% have a site within 1.5 miles.
 round(xyz[findInterval(c(1, 1.5),  xyz$dist), ], 3) 
 
 # plot is too busy for all groups at once so this is a way to tap through them 1 by 1
 these = c(names_d, names_d_subgroups)
 for (i in 1:length(these)) {
   readline("press any key to see the next plot")
   print(distance_by_group_plot(y$results_bybg_people, demogvarname = these[i]) )
 }
 

}
\seealso{
\code{\link[=plot_distance_mean_by_group]{plot_distance_mean_by_group()}}  \code{\link[=distance_by_group]{distance_by_group()}}
}
\keyword{internal}
